package com.qtyx.nms.ui.activity

import com.qtyx.nms.R
import com.qtyx.nms.mvp.model.bean.LoginBean
import com.qtyx.nms.mvp.model.network.RetrofitUtil
import com.qtyx.nms.mvp.presenter.LauncherPresenter
import com.qtyx.nms.mvp.presenter.LoginPresenter
import com.qtyx.nms.mvp.view.LauncherView
import com.qtyx.nms.mvp.view.LoginView
import com.qtyx.nms.ui.base.BaseActivity
import com.qtyx.nms.ui.base.BaseMVPActivity
import com.qtyx.nms.util.shared.AppInfoShared
import kotlinx.android.synthetic.main.ac_login.*

/**
 * 启动页
 */
class LauncherActivity : BaseMVPActivity<LauncherPresenter>(),LauncherView {
    override fun getLayoutId()= R.layout.ac_launcher
    override fun createPresenter()=LauncherPresenter(this)
    override fun initData() {
        isShowBack=false
        RetrofitUtil.connectTimeout=2
        presenter.autoLogin()
    }

    override fun loginSucceed(data: LoginBean) {
        //登录成功，保存数据
        AppInfoShared.saveToken(data.token)
        AppInfoShared.saveHospitalName(data.systemName)
        AppInfoShared.saveDeptId(data.deptId.toString())
        AppInfoShared.saveDeptName(data.deptName)
        AppInfoShared.saveServerDate(data.date)

        //两秒进入
        window.decorView.postDelayed({
            RetrofitUtil.setInstance(null)
            RetrofitUtil.connectTimeout=30
            startActivityAndFinish(HomePageActivity::class.java)
        },1*1000)
    }

    override fun loginFailure() {
        RetrofitUtil.setInstance(null)
        RetrofitUtil.connectTimeout=30
        startActivityAndFinish(LoginActivity::class.java)
    }

}